home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / whatview / whatis.e < prev    next >
Text File  |  1994-05-02  |  4KB  |  143 lines

  1.  
  2. OPT OSVERSION=37
  3.  
  4. CONST MAXPATH=250
  5.  
  6. ENUM ER_NONE,ER_BADARGS,ER_NOPORT,ER_PORT,ER_ARG
  7.  
  8. MODULE 'dos/dos','dos/dosasl','utility'
  9. MODULE 'eropenlib','exec/ports','exec/nodes','wvprefs'
  10. DEF whatviewport:PTR TO mp
  11. DEF dummyport:PTR TO mp
  12. DEF action[256]:STRING
  13. DEF currentdir[256]:STRING
  14. DEF file=FALSE
  15. PROC main() HANDLE /*"main()"*/
  16.     DEF myarg:PTR TO LONG,rdargs=NIL
  17.     DEF dirw[100]:STRING,fib:fileinfoblock
  18.     DEF lock
  19.     WriteF('WhatIs v0.1 © 1994 NasGûl.\n')
  20.     myarg:=[0,0,0,0]
  21.     IF (utilitybase:=OpenLibrary('utility.library',37))=NIL THEN Raise(ER_UTILITYLIB)
  22.     IF (whatviewport:=FindPort('WhatViewPort'))=NIL THEN Raise(ER_NOPORT)
  23.     IF (dummyport:=CreateMsgPort())=NIL THEN Raise(ER_PORT)
  24.     IF rdargs:=ReadArgs('DOSSIER,ACT/K,FLUSH/S,PREFS/S',myarg,NIL)
  25.         IF myarg[0] 
  26.             StrCopy(dirw,myarg[0],ALL)
  27.         ELSE
  28.             Raise(ER_ARG)
  29.         ENDIF
  30.         IF myarg[1] 
  31.             StrCopy(action,myarg[1],ALL)
  32.             UpperStr(action)
  33.         ELSE
  34.             StrCopy(action,'WHATVIEW',ALL)
  35.         ENDIF
  36.         IF myarg[2]
  37.             p_SendWhatviewMessage('FLUSH','SYS:')
  38.             Raise(ER_NONE)
  39.         ENDIF
  40.         IF myarg[3]
  41.             p_SendWhatviewMessage('PREFS','SYS:')
  42.             Raise(ER_NONE)
  43.         ENDIF
  44.         IF lock:=Lock('',-2)
  45.             NameFromLock(lock,currentdir,256)
  46.             UnLock(lock)
  47.         ENDIF
  48.         IF lock:=Lock(dirw,-2)
  49.             IF Examine(lock,fib)
  50.                 IF fib.direntrytype>0
  51.                     AddPart(dirw,'#?',100)
  52.                     file:=FALSE
  53.                 ELSE
  54.                     file:=TRUE
  55.                 ENDIF
  56.             ENDIF
  57.             UnLock(lock)
  58.         ENDIF
  59.         p_RecDir(dirw)
  60.         Raise(ER_NONE)
  61.     ELSE
  62.         Raise(ER_BADARGS)
  63.     ENDIF
  64. EXCEPT
  65.     IF rdargs THEN FreeArgs(rdargs)
  66.     IF dummyport THEN DeleteMsgPort(dummyport)
  67.     IF utilitybase THEN CloseLibrary(utilitybase)
  68.     SELECT exception
  69.         CASE ER_BADARGS;    WriteF('Mauvais Arguments.\n')
  70.         CASE ER_UTILITYLIB; WriteF('Utility.library v37+ ?.\n')
  71.         CASE ER_NOPORT;     WriteF('Port WhatViewPort inexistant.\n')
  72.         CASE ER_PORT;       WriteF('Impossible de créer un port de message.\n')
  73.         CASE ER_ARG;        WriteF('1 Argument manquant (Dossier ou Fichier ou Pattern).\n')
  74.     ENDSELECT
  75. ENDPROC
  76. PROC p_RecDir(dirr) HANDLE /*"p_RecDir(dirr)"*/
  77.   DEF er,i:PTR TO fileinfoblock,size=0,anchor=NIL:PTR TO anchorpath,fullpath
  78.   DEF pos,rdir[100]:STRING,reelname[256]:STRING
  79.   anchor:=New(SIZEOF anchorpath+MAXPATH)
  80.   anchor.breakbits:=4096
  81.   anchor.strlen:=MAXPATH-1
  82.   er:=MatchFirst(dirr,anchor)                   /* collect all strings */
  83.   WHILE er=0
  84.     fullpath:=anchor+SIZEOF anchorpath
  85.     i:=anchor.info
  86.     pos:=InStr(fullpath,i.filename,0)
  87.     IF pos<>0
  88.         MidStr(rdir,fullpath,0,pos)
  89.     ELSE
  90.         StrCopy(rdir,currentdir,ALL)
  91.     ENDIF
  92.     StringF(reelname,'\s',i.filename)
  93.     p_SendWhatviewMessage(reelname,rdir)
  94.     er:=MatchNext(anchor)
  95.   ENDWHILE
  96.   IF StrCmp(action,'WHATVIEW',8)
  97.       p_SendWhatviewMessage('WHATVIEW',0)
  98.   ELSEIF StrCmp(action,'INFO',4)
  99.       p_SendWhatviewMessage('INFO',0)
  100.   ELSEIF StrCmp(action,'ADDICON',7)
  101.       p_SendWhatviewMessage('ADDICON',0)
  102.   ELSEIF StrCmp(action,'EXECUTE',7)
  103.       p_SendWhatviewMessage('EXECUTE',0)
  104.   ELSEIF StrCmp(action,'QUIT',4)
  105.       p_SendWhatviewMessage('QUIT',0)
  106.   ENDIF
  107.   IF er<>ERROR_NO_MORE_ENTRIES THEN Raise(er)
  108.   MatchEnd(anchor)
  109.   Dispose(anchor)
  110.   anchor:=NIL
  111.   Raise(ER_NONE)
  112. EXCEPT                                  /* nested exception handlers! */
  113.   IF anchor THEN MatchEnd(anchor)
  114.   Raise(exception)  /* this way, we call _all_ handlers in the recursion  */
  115. ENDPROC size        /* and thus calling MatchEnd() on all hanging anchors */
  116. PROC p_SendWhatviewMessage(name,curdir) HANDLE /*"p_SendWhatviewMessage(name,curdir)"*/
  117.     DEF execmsg:PTR TO mn
  118.     DEF mymsg:PTR TO wvmsg
  119.     DEF node:PTR TO ln
  120.     mymsg:=New(SIZEOF wvmsg)
  121.     execmsg:=mymsg
  122.     node:=execmsg
  123.     node.type:=NT_MESSAGE
  124.     node.pri:=0
  125.     execmsg.replyport:=dummyport
  126.     mymsg.name:=name
  127.     mymsg.lock:=Lock(curdir,-2)
  128.     Forbid()
  129.     IF whatviewport
  130.         PutMsg(whatviewport,mymsg)
  131.     ENDIF
  132.     Permit()
  133.     IF whatviewport
  134.         WaitPort(dummyport)
  135.         GetMsg(dummyport)
  136.     ENDIF
  137.     Raise(ER_NONE)
  138. EXCEPT
  139.     IF mymsg.lock THEN UnLock(mymsg.lock)
  140.     IF mymsg THEN Dispose(mymsg)
  141. ENDPROC
  142.  
  143.